package producersConsumersTests.results;

import producersConsumersTests.utils.RunnableWithId;

/**
 * A ContainerEvent to mark an insertion to the container.
 * 
 */
public class EntranceEvent implements ContainerEvent {
	private final long time[];
	private final RunnableWithId task;
	private ExitEvent exit;

	public EntranceEvent(long time[], RunnableWithId task) {
		this.time = time;
		this.task = task;
	}

	@Override
	public long[] getTime() {
		return time;
	}

	@Override
	public RunnableWithId getDaddyTask() {
		return task;
	}

	@Override
	public boolean greaterThan(ContainerEvent event) {
		if (!(event instanceof EntranceEvent))
			throw new RuntimeException("Entrance and exits ");
		/*
		 * if (e1.vc[e1.tid] < e2.vc[e1.tid]) then e1 precedes e2 in the
		 * real-time order
		 * 
		 * if (e2.vc[e2.tid] < e1.vc[e2.tid]) then e2 precedes e1 in the
		 * real-time order
		 * 
		 * otherwise we know nothing about their real-time order relations.
		 */
		EntranceEvent e = (EntranceEvent) event;
		if (this.getTime()[(int) e.task.getId()] > e.getTime()[(int) e.task
				.getId()]) {
			return true;
		}
		return false;
	}

	public void setExit(ExitEvent e) {
		this.exit = e;
	}

	public ExitEvent getExit() {
		return exit;
	}
}
